package com.CGFrame.struts.action.categorySet;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Category;
import com.CGFrame.struts.POJOs.Catemodel;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.category.CateModelBean;
import com.CGFrame.struts.bean.category.CategoryBean;
import com.CGFrame.struts.bean.log.LogHistoryBean;

public class AddRelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String modelId=request.getParameter("modelId");
		String cate1=request.getParameter("cate1");
		String cate2=request.getParameter("cate2");
		
		
		CategoryBean cb=new CategoryBean();
		Category category1=cb.getCateById(cate1);
		Category category2=cb.getCateById(cate2);
		
		CateModelBean cmb=new CateModelBean(Integer.valueOf(modelId));
		String result=cmb.addCateModelRel(category1, category2);
		if ( "SUCCESS".equals(result) ){
			LogHistoryBean logBean = new LogHistoryBean();
			String regUserId = (String)request.getSession().getAttribute("RegUserID");
			logBean.saveByReguserId(regUserId, LogHistoryBean.ADD, category1.getCategoryEnglishName()+"-->"+category2.getCategoryEnglishName(),"Catemodel",Integer.valueOf(modelId) );
		}
		request.setAttribute("result", result);
		
		request.setAttribute("modelId", modelId);
		
		return mapping.findForward("detail");
	}
	
}
